﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NENAData.Factory;
using NENAData.EF;
using NENAData.Transactions;

namespace NENAData.NENAMember
{
    public class Ef
    {
        private static NENA_MembershipEntities GetConnection()
        {
            var x = new SQLMembership();
            return x.DBConnection();
        }

        public EF.Member GetMember(int MemberId)
        {

            NENA_MembershipEntities db = GetConnection();

            //get the transaction object
            //TransactionList transactionList = new TransactionList();
            //Transaction Transaction = transactionList.GetTransaction(transactions);

            //join t in db.Transactions on e.Transaction.TransactionID_NENA equals t.TransactionID_NENA
            //e.Transaction == Transaction
            EF.Member Member = (from m in db.Members
                                                    where m.Member_ID == MemberId
                                                    select m).SingleOrDefault();
            return Member;
        }

        public void UpdateMemberOnApplication(EF.Member Member)
        {

            EF.Member currentMember = GetMember(Member.Account_ID);

            NENA_MembershipEntities db = GetConnection();

            EF.Member DbMember = (from m in db.Members
                                  where m.Member_ID == Member.Member_ID
                                select m).SingleOrDefault();

            DbMember.CS_UserID = Member.CS_UserID;
            DbMember.CS_UserName = Member.CS_UserName;
            DbMember.Last_Modified = Member.Last_Modified;

            //get the transaction object
            //TransactionList transactionList = new TransactionList();
            //Transaction Transaction = transactionList.GetTransaction(transactions);

            //join t in db.Transactions on e.Transaction.TransactionID_NENA equals t.TransactionID_NENA
            //e.Transaction == Transaction
            db.SaveChanges();
        }

    }
}
